/****************************************************************************
**                                                                         **
**                         PSSDK HNLBAdapter module                        **
**            Copyright (c) 1997 - 2006 microOLAP Technologies LTD,        **
**                       Khalturin A.P., Naumov D.A.                       **
**                               Header File                               **
**                                                                         **
****************************************************************************/

//---------------------------------------------------------------------------
#ifndef __HN_PSSDK_LBADAPTER_H__
#define __HN_PSSDK_LBADAPTER_H__ 
//---------------------------------------------------------------------------

//---------------------------------------------------------------------------
// Class CHNLBAdapter
//---------------------------------------------------------------------------
class CHNLBAdapter
{
private:
    HANDLE hLbAdp;

public:
    //###########################################################################
    //    Create & Destroy
    //###########################################################################

    //---------------------------------------------------------------------------
    // v2.3 - LbAdpCreate - Creates an HNLBAdapter object.
    CHNLBAdapter() { hLbAdp = LbAdpCreate(); }

    //---------------------------------------------------------------------------
    // v2.3 - LbAdpDestroy - Destroys the HNLBAdapter object.
    ~CHNLBAdapter() { LbAdpDestroy(hLbAdp); }

public:
    //###########################################################################
    //    Additionals methods
    //###########################################################################
    BOOL     IsValid() { return (BOOL)(hLbAdp != NULL); }
    HANDLE   Get_Handle() { return hLbAdp; }
    operator HANDLE() { return hLbAdp; }

public:
    //###########################################################################
    //    Methods of redirect
    //###########################################################################

    //---------------------------------------------------------------------------
    // v2.3 - LbAdpOpenAdapter - Opens loopback adapter for TCP/UDP traffic capturing and tracking of TCP sessions.
    DWORD OpenAdapter() 
    { return LbAdpOpenAdapter(hLbAdp); }

    //---------------------------------------------------------------------------
    // v2.3 - LbAdpCloseAdapter - Closes the loopback adapter, stops receiving of the local traffic and sessions tracking.
    DWORD CloseAdapter() 
    { return LbAdpCloseAdapter(hLbAdp);} 

    //---------------------------------------------------------------------------
    // v2.3 - LbAdpGetOpenTime - Returns the time of the latest opening of the loopback adapter.
#ifdef _WIN64
    LONGLONG GetOpenTime() 
    { return LbAdpGetOpenTime(hLbAdp); }
#else
    DWORD GetOpenTime(DWORD *pHiValue) 
    { return LbAdpGetOpenTime(hLbAdp,pHiValue); }
#endif //_WIN64

    //---------------------------------------------------------------------------
    // v2.3 - LbAdpGetProcessNameByID - Returns the process name by the process identifier (PID).
    DWORD GetProcessNameByID(DWORD ProcessID, LPSTR Name, DWORD Size) 
    { return LbAdpGetProcessNameByID(ProcessID,Name,Size); } 

    //---------------------------------------------------------------------------
    // v2.3 - LbAdpGetProcessFileByID - Returns the exefile name by the process identifier (PID).
    DWORD GetProcessFileByID(DWORD ProcessID, LPSTR Name, DWORD Size) 
    { return LbAdpGetProcessFileByID(ProcessID,Name,Size); } 

    //---------------------------------------------------------------------------
    // v2.3 - LbAdpSetOnTcpPacketRecv - Sets the OnTcpPacketReceive event.
    FARPROC SetOnTcpPacketRecv(FARPROC pfOnTcpPacketReceive, DWORD_PTR Param) 
    { return LbAdpSetOnTcpPacketRecv(hLbAdp,pfOnTcpPacketReceive,Param); }

    //---------------------------------------------------------------------------
    // v2.3 - LbAdpSetOnUdpPacketRecv - Sets the OnUdpPacketReceive event.
    FARPROC SetOnUdpPacketRecv(FARPROC pfOnUdpPacketReceive, DWORD_PTR Param) 
    { return LbAdpSetOnUdpPacketRecv(hLbAdp,pfOnUdpPacketReceive,Param); }

    //---------------------------------------------------------------------------
    // v2.3 - LbAdpSetOnThreadBegin - Sets the OnThreadBegin event.
    FARPROC SetOnThreadBegin(FARPROC pfOnThreadBegin, DWORD_PTR Param) 
    { return LbAdpSetOnThreadBegin(hLbAdp,pfOnThreadBegin,Param); }

    //---------------------------------------------------------------------------
    // v2.3 - LbAdpSetOnThreadEnd - Sets the OnThreadEnd event.
    FARPROC SetOnThreadEnd(FARPROC pfOnThreadEnd, DWORD_PTR Param) 
    { return LbAdpSetOnThreadEnd(hLbAdp,pfOnThreadEnd,Param); }

    //---------------------------------------------------------------------------
    // v2.3 - LbAdpSetOnConnect - Sets the OnConnect event.
    FARPROC SetOnConnect(FARPROC pfOnConnect, DWORD_PTR Param) 
    { return LbAdpSetOnConnect(hLbAdp,pfOnConnect,Param); }

    //---------------------------------------------------------------------------
    // v2.3 - LbAdpSetOnDisconnect - Sets the OnDisconnect event.
    FARPROC SetOnDisconnect(FARPROC pfOnDisconnect, DWORD_PTR Param) 
    { return LbAdpSetOnDisconnect(hLbAdp,pfOnDisconnect,Param); }
};

//---------------------------------------------------------------------------
#endif // __HN_PSSDK_LBADAPTER_H__ 
//---------------------------------------------------------------------------
